package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.CourseOrder;
import cn.wolfcode.crm.mapper.CourseOrderMapper;
import cn.wolfcode.crm.mapper.CustomerMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ICourseOrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CourseOrderServiceImpl implements ICourseOrderService {
    @Autowired
    private CourseOrderMapper courseOrderMapper;
    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public void save(CourseOrder courseOrder) {
        //保存时插入时间
        Date date = new Date();
        courseOrder.setInputTime(date);
        //将客户状态改为正式客户
        Long id = courseOrder.getCustomer().getId();
        customerMapper.updateCustomerStatus(id);
        courseOrderMapper.insert(courseOrder);
    }

    @Override
    public void delete(Long id) {
        courseOrderMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(CourseOrder courseOrder) {

        courseOrderMapper.updateByPrimaryKey(courseOrder);
    }

    @Override
    public CourseOrder get(Long id) {
        return courseOrderMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<CourseOrder> list() {
        return courseOrderMapper.selectAll();
    }

    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<CourseOrder> list = courseOrderMapper.selectForList(qo);
        return new PageInfo(list);
    }


}
